package com.dc2013.followme;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockActivity;
import com.actionbarsherlock.internal.widget.IcsSpinner;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.actionbarsherlock.view.MenuItem;
import com.android.volley.AuthFailureError;
import com.android.volley.RequestQueue;
import com.android.volley.VolleyError;
import com.android.volley.Response.ErrorListener;
import com.android.volley.Response.Listener;
import com.android.volley.toolbox.StringRequest;
import com.dc2013.adapter.LikeAdapter;
import com.dc2013.adapter.MainAdapter;
import com.dc2013.util.URLString;

import android.media.JetPlayer;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ViewFlipper;

public class ListHome_Activity extends SherlockActivity 
{


	private ActionBar actionbar;
	private View custom_actionbar_layout;
	private String nickName;
	private LayoutInflater inflater;
	private TextView actionbar_title;
	private LinearLayout actionbar_menu;
	
	private ImageView menu1,menu2,menu3;
	private View view_for_click;
	private ArrayList<ListItem> list_arrayList;
	private ArrayList<ImageItem> img_arrayList;
	private ImageItem img_item;
	private ListItem list_item;
	private MainAdapter mainAdapter;
	
	
	
	private RefreshableListView homeList;
	
	private RequestQueue queue;
	private String access_Token;
	ArrayList<ListItem> getMainListData(final int page) {
		StringRequest request = new StringRequest(URLString.MAIN+URLString.REFRESH_MAIN_LIST, 
		new Listener<String>() {

			@Override
			public void onResponse(String response) 
			{
				try
				{
					JSONObject obj = new JSONObject(response);
					Log.d("HttpResult",response);
					
					int message = obj.getInt("Message");
					
					if(message == 13)
					{
						JSONArray main_image_items = obj.getJSONArray("user_like_list");
						for(int i=0; i<main_image_items.length(); i++)
						{
							
						}
					}
					
					
				}
				catch(JSONException e)
				{
					
				}
				
				
			}
		},
		new ErrorListener() {

			@Override
			public void onErrorResponse(VolleyError arg0) {
				// TODO 자동 생성된 메소드 스텁
				
			}
		}){
			@Override
			protected Map<String, String> getParams() throws AuthFailureError {
				// TODO 자동 생성된 메소드 스텁
				Map<String, String> param = new HashMap<String, String>();
				param.put("access_token",access_Token);
				param.put("page_number", ""+page);
				return param;
			}
		};
		queue.add(request);
		
		return null;
		
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) 
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_home_);
		Intent get = getIntent();
		access_Token = get.getStringExtra("access_token");
		
		
		inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		
		
		nickName = "춤추며 밥먹는 사자 ";
		
		//액션바 설정부분 
		actionbar = getSupportActionBar();
		actionbar.setDisplayShowTitleEnabled(false);
		actionbar.setDisplayShowHomeEnabled(false);
		

		custom_actionbar_layout = inflater.inflate(R.layout.actionbar_layout,null);
		actionbar_title = (TextView)custom_actionbar_layout.findViewById(R.id.actionbar_title);
		actionbar_menu = (LinearLayout)findViewById(R.id.actionbar_menu);
		view_for_click = (View)findViewById(R.id.view_for_click);
		
		menu1 = (ImageView)findViewById(R.id.topic);
		menu2 = (ImageView)findViewById(R.id.fun_list);
		menu3= (ImageView)findViewById(R.id.photo_list);
		
		
		
		//액션바 메뉴 설정
		actionbar_title.setText(nickName);
		actionbar_title.setOnClickListener(actionbarClick);
		view_for_click.setOnClickListener(viewClick);
		
		menu1.setOnClickListener(menuClick);
		menu2.setOnClickListener(menuClick);
		menu3.setOnClickListener(menuClick);
		
		
		actionbar.setCustomView(custom_actionbar_layout,
				new ActionBar.LayoutParams(ActionBar.LayoutParams.MATCH_PARENT,
						ActionBar.LayoutParams.MATCH_PARENT));
		actionbar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
		
		//리스트뷰
		homeList = (RefreshableListView)findViewById(R.id.home_list);
		img_arrayList = new ArrayList<ImageItem>();
		
		//이미지 아이템 생성
	//	img_item = new ImageItem();
		img_arrayList.add(img_item);
		
		//리스트 아이템에 이미지아이템어레이리스트 넣고 
		list_item = new ListItem(img_arrayList);
		
		//리스트아이템 어레이리스트에 추가
		list_arrayList = new ArrayList<ListItem>();
		list_arrayList.add(list_item);
		
		//어댑터 설정 
		mainAdapter = new MainAdapter(this,R.layout.list_type_main,list_arrayList);
		
		homeList.setAdapter(mainAdapter);
		
		
	

	}
	

	private OnClickListener actionbarClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{
			actionbar_menu.setVisibility(View.VISIBLE);
			view_for_click.setVisibility(View.VISIBLE);

		}
	};
	
	private OnClickListener viewClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{
			actionbar_menu.setVisibility(View.GONE);
			view_for_click.setVisibility(View.GONE);
			
		}
	};
	
	
	private OnClickListener menuClick = new OnClickListener() 
	{
		
		@Override
		public void onClick(View v) 
		{
			
			switch(v.getId())
			{
			case R.id.topic:
				Intent i = new Intent(ListHome_Activity.this,AddSubject_Activity.class);
				startActivity(i);
				break;
			case R.id.fun_list:
				i = new Intent(ListHome_Activity.this,ListLike_Activity.class);
				startActivity(i);
				break;
			case R.id.photo_list:
				i = new Intent(ListHome_Activity.this,ListUploaded_Activity.class);
				startActivity(i);
				break;
			}
			
		}
	};
	
	
	
	
	


	
}
